package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.entity.MapEntity;
import com.baihan.angus.app.game.common.util.ImageLoader;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class DmMapAdp extends BaseAdp<MapEntity, DmMapAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dm_map, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = holder;

        MapEntity item = getItem(position);

        vh.tvTitle.setText(item.getTitle());

        ImageLoader.loadImage(BaseApplication.getApplication().getApplicationContext(),
                vh.ivMap, item.getUrl().get(0).getUrl(), R.mipmap.ic_test_bg, 0);

        if (item.getIs_show() == 0) {//0-未展示 1-已展示
            vh.tvShow.setEnabled(true);
        } else {
            vh.tvShow.setEnabled(false);
        }

        vh.tvShow.setOnClickListener(v -> {
            mOnItemClickListener.onShow(position);
        });

        vh.llMap.setOnClickListener(v -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvTitle, tvShow;
        QMUIRadiusImageView ivMap;
        LinearLayout llMap;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tvTitle);
            tvShow = itemView.findViewById(R.id.tvShow);
            ivMap = itemView.findViewById(R.id.ivMap);
            llMap = itemView.findViewById(R.id.llMap);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onShow(int position);
        void onItemClick(int positon);
    }
}
